<template>
  <div class="network">
      <img :src="network" width="50%" height="50%" alt="" />
    </div>
</template>

<script>
export default {
  name: "ResourceList",
  mounted() {
    this.getResouceList();
  },
  data() {
    return {
      form: {
        keyword: "",
      },
      network: require("C:/Users/81437/Downloads/drst-front-feature-chenjinqian/drst-front-feature-chenjinqian/src/assets/1.jpeg"),
      tableData: [],
      tableViewData: [],
      pageSize: 10,
      pageNum: 1,
    };
  },
  methods: {
    handleSizeChange(val) {
      this.tableViewData = [];
      this.pageSize = val;
      for (
        var i = (this.pageNum - 1) * this.pageSize;
        i < this.pageNum * this.pageSize;
        i++
      ) {
        if (this.tableData[i]) {
          this.tableViewData.push(this.tableData[i]);
        }
      }
      console.log(this.tableViewData);
    },
    handleCurrentChange(val) {
      this.tableViewData = [];
      this.pageNum = val;
      for (
        var i = (this.pageNum - 1) * this.pageSize;
        i < this.pageNum * this.pageSize;
        i++
      ) {
        if (this.tableData[i]) {
          this.tableViewData.push(this.tableData[i]);
        }
      }
      console.log(this.tableViewData);
    },
    getResouceList() {
      console.log("6666777");
      this.GLOBAL.web3.eth.getAccounts().then((res) => {
        this.GLOBAL.contract.methods
          .showAllResources(this.$route.query.username)
          .call({ from: res[0] })
          .then((res) => {
            console.log("res666:", res[0]);
            this.tableData = res[0];
            for (var i = 0; i < 10; i++) {
              if (res[i]) {
                this.tableViewData.push(res[i]);
              }
            }
          })
          .catch((err) => {
            console.log("error:", err);
          });
      });
    },
    follow(row) {
      console.log("row:", row.index);
      this.GLOBAL.web3.eth.getAccounts().then((res) => {
        this.GLOBAL.contract.methods
          .followResource(this.$route.query.username, row.index) //这个合约调用要修改
          .send({ from: res[0] })
          .then((res) => {
            console.log("res222:", res);
          });
      });
    },
  },
};
</script>

<style>
</style>
